# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings

from scipy.optimize import curve_fit
import numpy as np
import matplotlib.pyplot as plt

t = np.array(list(range(1790,2000,10)))
x = [3.9,5.3,7.2,9.6,12.9,17.1,23.2,31.4,38.6,50.2,62.9,
     76,92,106.5,132.2,131.7,150.7,179.3,204.0,226.5,251.4]

t_0 = t[0]
x_0 = x[0]

def func(t_i,x_m,r):
    return x_m/(1+(x_m/x_0 -1) * np.exp(-r * (t_i - t_0)))

param_bounds =  ([-np.inf,0],[np.inf,1])
x_m,r = curve_fit(func,t,x,bounds=param_bounds)[0]

x_predict = []
for i in t:
    x_predict.append(func(i,x_m,r))

plt.plot(t,x)
plt.plot(t,x_predict)
plt.show()

print('------------------------')
print('2021', func(2021,x_m,r))
print('2015',func(2015,x_m,r))